#include "Scanner.h"
#include "Parser.h"

#include <fstream>
#include <iostream>

  using namespace std;

  int main(int argv, char* args[]) {

    if(argv != 3) {
      cout << "Usage: ./compiler <grammar_file> <input_file>" << endl;
      return -1;
    }

    //Try to parse sample grammar                                                                                                                                              
    Scanner *grammar_reader = new Scanner();
    int result = grammar_reader->readFile(args[1]);

    if(result != 1) {
      printf("Can't parse Grammar!\n Result: %d\n", result);
      return -1;
    }

    //If File is able to be read, then read grammar + print out details                                                                                                        
    grammar_reader->readGrammar();
    grammar_reader->printVectors();

    vector<string>* tokens = grammar_reader->getTokens();
    vector<string>* nonterms = grammar_reader->getNon_terminals();

    //File Reader                                                                                                                                                              
    Scanner *intput_reader = new Scanner();
    result = intput_reader->readFile(args[2]);

    if(result != 1) { //file exists                                                                                                                                            
      printf("Can't parse Input File!\n Result: %d\n", result);
      return -1;
    }

    //Set up Parser Object and tell it to go via parse method
    Parser parse(*(grammar_reader->getGrammar()), args[2], *tokens, *nonterms, grammar_reader->getStartState());
    parse.parse();

  return 0;
}
